import requests
from api.login_api import Mepsking_Login
from config import Base_Host
class Region_Api:
    def inquire_info(self,countryCode,token):
        url=Base_Host+'/api/system/region/getRegionCascade?countryCode={}'.format(countryCode)
        header_dict={'accesstoken':token,'accept-language':'zh-CN,zh;q=0.9'}
        resp=requests.get(url=url,headers=header_dict)
        print('请求地区接口返回的数据为：{}'.format(resp.json()))
        return resp
    # def country_id(self,countryCode,token):
    #     country_id=[]
    #     country=self.inquire_info(countryCode,token)
    #     id=country.json().get('result')
    #     print(len(id))
    #     for i in range(len(id)):
    #         country_id.append(id[i].get('id'))
    #     print('获取到的country_id为{}'.format(country_id))
    #     return country_id
    def region_name(self,countryCode,token):
        region_name=self.inquire_info(countryCode,token)
        region_name=region_name.json().get('result')[0].get('parentRegionName')
        print('获取到的region_name为：{}'.format(region_name))
        return region_name
    # def distict(self,countryCode,token):
    #     get_distict=self.inquire_info(countryCode,token)
    #     get_distict=get_distict.json().get('result')
    def country_id(self,countryCode,token):
        country_id=[]
        country=self.inquire_info(countryCode,token)
        id=country.json().get('result')
        if len(id)!=0:
            return countryCode
if __name__ == '__main__':
    login=Mepsking_Login()
    json_dict = {"password": "d4129fb5f167eda9d7492d7d671133e4", "username": "2524726232@qq.com"}
    token=login.token(json_dict)
    a=[]
    v=['AF', 'AZ', 'BH', 'BT', 'KH', 'IQ', 'KZ', 'KW', 'KG', 'LB', 'MV', 'TJ', 'TM', 'YE', 'CR', 'SV', 'AL', 'AD', 'AM', 'BY', 'GI', 'IS', 'XZ', 'MD', 'MC', 'LI', 'SM', 'RS', 'VA', 'SD', 'CY', 'MT']
    for i in v:
        resp=Region_Api()
        test=resp.country_id(i,token)
        a.append(test)
    print(a)



